﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SPFarmModeler.Common;
using System.Reflection;

namespace SPFarmModeler.Business
{
    [Serializable]
    public abstract class SPService
    {
        public TypeSPService Type
        {
            get
            {
                System.Type cType = this.GetType();
                if (cType == typeof(SPService_Central_Administration)) return TypeSPService.Central_Administration;
                if (cType == typeof(SPService_Document_Conversions_Launcher_Service)) return TypeSPService.Document_Conversions_Launcher_Service;
                if (cType == typeof(SPService_Document_Conversions_LoadBalancer_Service)) return TypeSPService.Document_Conversions_LoadBalancer_Service;
                if (cType == typeof(SPService_Excel_Calculation_Services)) return TypeSPService.Excel_Calculation_Services;
                if (cType == typeof(SPService_Office_SharePoint_Server_Search)) return TypeSPService.Office_SharePoint_Server_Search;
                if (cType == typeof(SPService_Windows_SharePoint_Services_Help_Search)) return TypeSPService.Windows_SharePoint_Services_Help_Search;
                if (cType == typeof(SPService_Windows_Sharepoint_Services_Incoming_Email)) return TypeSPService.Windows_Sharepoint_Services_Incoming_Email;
                if (cType == typeof(SPService_Windows_Sharepoint_Services_Web_Application)) return TypeSPService.Windows_Sharepoint_Services_Web_Application;
                throw new Exception("Type inconnu");
            }
        }

        public string Name { get; set; }

        /// <summary>
        /// Constructeur
        /// </summary>
        public SPService()
        {
        }

        public static List<SPService> GetServices()
        {
            List<SPService> services = new List<SPService>();
            try
            {
                Assembly ass = Assembly.LoadFrom("SPFarmModeler.Core.dll");
                Type[] assTypes = ass.GetTypes();
                foreach (Type individualType in assTypes)
                {
                    if (individualType.BaseType == typeof(SPService))
                        services.Add((SPService)Activator.CreateInstance(individualType));
                }
            }
            catch { }

            return services;
        }
    }

    [Serializable]
    public class ServiceList : List<Server>
    {
        
    }
}
